import Vue from 'vue'
import Router from 'vue-router'
import { getSonglistDetail } from '../api/api'

Vue.use(Router)

export default new Router({
    routes: [
        {
            path: '/',
            redirect: '/index'
        },
        {
            path: '/index',
            name: 'Index',
            component: resolve => require(['@/page/index/index'],resolve),
            children: [
                {
                    path: 'detail',
                    component: resolve=> require(['@/page/songlist-detail/songlist-detail'],resolve)
                },
                {
                    path: 'more',
                    component: resolve=> require(['@/page/more-songlist/more-songlist'],resolve)
                }
            ]
        },
        {
            path: '/rank',
            name: 'Rank',
            component: (resolve)=> {
                require(['@/page/rank/rank'],resolve)
            },
            children:[
                {
                    path:'rank-detail',
                    component:(resolve)=> {
                        require(['@/page/rank-detail/rank-detail'],resolve)
                    }
                }
            ]
        },
        {
            path: '/singer',
            name: 'Singer',
            component: (resolve)=> {
                require(['@/page/singer/singer'],resolve)
            },
            children: [
                {
                    path: 'singer-detail',
                    component:resolve=> require(['@/page/singer-detail/singer-detail'],resolve)
                }
            ]
        },
        {
            path: '/search',
            name: 'Search',
            component: (resolve)=> {
                require(['@/page/search/search'],resolve)
            }
        },
        {
            path: '/user',
            name: 'User',
            component: (resolve)=> {
                require(['@/page/user/user'],resolve)
            }
        },
        {
            path: '/demo',
            name: 'Demo',
            component: (resolve)=> {
                require(['@/page/demo/demo'],resolve)
            }
        },
        
    ]
})

//解决点击同一个路由报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}



